package unit2.creater;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import unit2.db.*;

public class CreaterUsers {
	private final String filename = "users.ser";
	
	private Users usersFromFile() throws ClassNotFoundException, IOException
	{
		@SuppressWarnings("resource")
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));
		Users m  = (Users) ois.readObject();
		return m;
	}
	
	private void usersInFile( Users usersForFile) throws IOException{
		FileOutputStream fos = new FileOutputStream(filename);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(usersForFile);
		oos.flush();
		oos.close();
	}
	
	
	public static  void  writeUsersInFile(Users dbOfUsers ) throws IOException{
		CreaterUsers temp= new CreaterUsers();
		temp.usersInFile(dbOfUsers);
	}
	
	public static Users readUsersFromFile() throws ClassNotFoundException, IOException{
		CreaterUsers temp= new CreaterUsers();
		Users dbOfUsers; 
		dbOfUsers= (Users) temp.usersFromFile();
		return dbOfUsers;
	}	
}
